package OwnSideObject;

import com.sxt.AnimationObj;
import com.sxt.GameObject;
import com.sxt.GameWin;
import enemyObject.Enemy2Obj;
import enemyObject.EnemyObj;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class BulletObj extends OwnSideObject{
    static int MY_BULLET_WIDTH = 5; //我方子弹的宽度
    static int MY_BULLET_HEIGHT = 11; //我方子弹的高度
    //弹药标记
    public int flag;
    public BulletObj() {
        super();
    }

    public BulletObj(String image, GameWin frame) {
        super(image, frame);
    }

    public BulletObj(String image, int x, int y, int speedY, GameWin frame,int flag) {
        super(image, x, y, speedY, frame);
        this.flag=flag;
    }

    @Override
    public void paintSelf(Graphics s) {
        s.drawImage(image,x,y,null);

        //炸弹清屏
        if (this.y<240&&this.flag==2){
            this.Frame.removeList.add(this);
            for (EnemyObj enemyObj:this.Frame.enemy1ObjList){
                this.Frame.animationObjs.add(new AnimationObj(EnemyObj.AnimationPath,EnemyObj.PicFormat,EnemyObj.AnimationNums,enemyObj.x,enemyObj.y,this.Frame));
                enemyObj.x=-200;
                enemyObj.y=-200;
                this.Frame.removeList.add(enemyObj);
                this.Frame.bacGroundObj.score++;
            }
            for (Enemy2Obj enemy2Obj:this.Frame.enemy2ObjList){
                this.Frame.animationObjs.add(new AnimationObj(Enemy2Obj.AnimationPath,Enemy2Obj.PicFormat,Enemy2Obj.AnimationNums,enemy2Obj.x,enemy2Obj.y,this.Frame));
                enemy2Obj.x=-200;
                enemy2Obj.y=-200;
                this.Frame.removeList.add(enemy2Obj);
                this.Frame.bacGroundObj.score+=5;
            }
            if (this.Frame.bossObj!=null)
                this.Frame.bossObj.life-=20;
        }
        //我方子弹越界消失
        if (y<0||x<0||x>GameWin.WINDOW_WIDTH){
            x = GameWin.MY_BULLET_VANISH_LOCATION_X;
            y = GameWin.MY_BULLET_VANISH_LOCATION_Y;
            this.Frame.removeList.add(this);
        }
        //子弹移动
        y -= speedY;
        x +=speedX;
    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(x,y,MY_BULLET_WIDTH,MY_BULLET_HEIGHT);
    }
    @Override
    public void DeBug() {
        System.out.println("BulletObj Class");
    }
}
